package com.edu.swu.service.imp;

import com.edu.swu.dao.IAccountDao;
import com.edu.swu.domain.Account;
import com.edu.swu.service.IAccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.lang.annotation.Annotation;
@Service("accountService")
@Transactional
public class AccountServiceImpImp implements IAccountService {

    private IAccountDao accountDao;



    public Account findById(Integer accountId) {
        return accountDao.findById(accountId);
    }

    public Account findByName(String accountName) {
        return accountDao.findByName(accountName);
    }

    public void saveAccount(Account account) {
        accountDao.updateAccount(account);
    }

    public void transfer(String sourceName, String targetName, int increments) {
        Account sourceAccount=accountDao.findByName(sourceName);
        Account targetAccount=accountDao.findByName(targetName);
        sourceAccount.setUserAge(sourceAccount.getUserAge()-increments);
        targetAccount.setUserAge(targetAccount.getUserAge()+increments);
        accountDao.updateAccount(sourceAccount);
//        int i=1/0;
        accountDao.updateAccount(targetAccount);

    }
}
